package com.april.pattern.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/07/04 16:04
 * @description 享元的工厂类
 */
public class ChessFlyWeightFactory {
    private static Map<String, ChessFlyWeight> chessFlyWeightMap = new HashMap<>(16);

    public static ChessFlyWeight getChessFlyWeight(String color) {
        if (chessFlyWeightMap.get(color) != null) {
            return chessFlyWeightMap.get(color);
        } else {
            ChessFlyWeight chessFlyWeight = new ConcreteChessImpl(color);
            chessFlyWeightMap.put(color, chessFlyWeight);
            return chessFlyWeight;
        }
    }
}
